package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buba.service.AccumulationService;
import common.R;
import entity.salary.Accumulation;
import entity.salary.dto.InsuranceDto;
import entity.salary.dto.accumulationDto;
import entity.salary.dto.socialDto;
import entity.salary.vo.socialDetailedVo;
import entity.staff.dto.saveAccountDto;
import entity.staff.dto.withAccumPerDto;
import entity.staff.dto.withSocialPerDto;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;



import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.PageResult;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-03-14
 */
@RestController
@RequestMapping("/accumulation")
public class AccumulationController {

    @Resource
    private AccumulationService accumulationService;

    /* *
     * @Author: beisheng
     * @Descriprion: 根据选择的公积金方案查询缴费明细
     * @Date: 2023/3/20 19:55
     * @Return: common.R
     * @Param: [socilaId]
     */

    @GetMapping("/accumDetailed/{accumId}")
    public R accumDetailed(@PathVariable("accumId") Integer accumId){
        List<socialDetailedVo> socialDetailedVos = accumulationService.accumDetailed(accumId);
        return R.success(socialDetailedVos);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 添加人员到公积金方案
     * @Date: 2023/3/17 9:52
     * @Return: common.R
     * @Param: [saveAccountDto]
     */

    @PostMapping("/saveAccuntToAccum")
    public R saveAccuntToAccum(@RequestBody saveAccountDto saveAccountDto){
        accumulationService.saveAccuntToAccum(saveAccountDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据公积金方案名称查看公积金方案中是否包含当前公积金方案
     * @Date: 2023/3/19 18:36
     * @Return: common.R
     * @Param: [schemeName]
     */

    @GetMapping("/judgeSchemeAcc")
    public R judgeSchemeAcc(@RequestParam String schemeName){
        Boolean b = accumulationService.judgeSchemeAcc(schemeName);
        return R.success(b);
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 添加公积金方案,并添加公积金方案配置信息，添加关联人员
     * @Date: 2023/3/16 18:31
     * @Return: common.R
     * @Param: [insuranceDto]
     */

    @PostMapping("/insertaccumulation")
    public R insertSocial(@RequestBody accumulationDto accumulationDto){
        accumulationService.insertaccumulation(accumulationDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 分页查询公积金方案
     * @Date: 2023/3/15 19:00
     * @Return: common.R
     * @Param: []
     */

    @PostMapping("/findAllAccumulation")
    public R findAllAccumulation(@RequestBody socialDto socialDto){
        PageResult socialVos = accumulationService.findAllAccumulation(socialDto);
        return R.success(socialVos);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据公积金方案ID查询当前社保方案关联的人员信息
     * @Date: 2023/3/16 10:47
     * @Return: common.R
     * @Param: [socialPerDto]
     */

    @PostMapping("/findWithAccumPer")
    public R findAllSocial(@RequestBody withAccumPerDto accumPerDto){
        PageResult WithAccumPerDto = accumulationService.withAccumPerDto(accumPerDto);
        return R.success(WithAccumPerDto);
    }

    /**
     * 功能描述: 新增或更新
     *
     * @param accumulation
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/save")
    public R save(@RequestBody Accumulation accumulation) {
        accumulationService.saveOrUpdate(accumulation);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 删除公积金方案,并删除关联方案配置信息
     * @Date: 2023/3/17 10:26
     * @Return: common.R
     * @Param: [id]
     */

    @GetMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        accumulationService.removeAccum(id);
        return R.success();
    }

  /* *
   * @Author: beisheng
   * @Descriprion: 批量逻辑删除公积金方案并逻辑删除关联配置方案信息
   * @Date: 2023/3/19 19:01
   * @Return: common.R
   * @Param: [ids]
   */

    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody Map<String,Object> map) {
        List<Integer> ids = (List<Integer>) map.get("ids");
        accumulationService.removeAccumByIds(ids);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 更改公积金方案状态
     * @Date: 2023/3/17 10:43
     * @Return: common.R
     * @Param: [id]
     */

    @PostMapping("/updateAccumStatus")
    public R updateAccumStatus(@RequestBody Map<String,Object> map){
        accumulationService.updateAccumStatus(map);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 修改公积金方案及公积金方案配置信息及关联人员
     * @Date: 2023/3/17 11:21
     * @Return: common.R
     * @Param: [insuranceDto]
     */

    @PostMapping("/updateAccum")
    public R updateAccum(@RequestBody accumulationDto accumulationDto){
        accumulationService.updateAccum(accumulationDto);
        return R.success();
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(accumulationService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(accumulationService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: zl
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<Accumulation> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(accumulationService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据公积金ID查询关联人员和关联险种信息
     * @Date: 2023/4/6 10:47
     * @Return: common.R
     * @Param: [socialId]
     */

    @GetMapping("/selAccumAndPeopleAndSocialFile/{socialId}")
    public R selAccumAndPeopleAndSocialFile(@PathVariable("socialId") Integer socialId){
        accumulationDto accumulationDto =  accumulationService.selAccumAndPeopleAndSocialFile(socialId);
        return R.success(accumulationDto);

    }


}
